package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.CenterBean02;
import com.lwj.liwanjia.bean.PersonalHomeBean;
import com.lwj.liwanjia.config.OnItemClickListener;

import java.util.List;

/**
 * Created by 001 on 2017/9/9.
 */

public class ShouCangBaoBeiAdapter extends RecyclerView.Adapter<ShouCangBaoBeiAdapter.ViewHolder> {

    private Context mContext;
    private List<CenterBean02.DataBean> mList;
    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public ShouCangBaoBeiAdapter(Context mContext, List<CenterBean02.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public ShouCangBaoBeiAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_wo_de_shou_cang_bao_bei, parent, false);

        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(ShouCangBaoBeiAdapter.ViewHolder holder, final int position) {

        CenterBean02.DataBean dataBean = mList.get(position);

        Glide.with(mContext).load(dataBean.getImgUrl()).into(holder.iv_photo);
        holder.tv_name.setText(dataBean.getCommodityName());
        holder.tv_content.setText(dataBean.getCommodityInfo());
        holder.tv_money.setText("¥" + dataBean.getPrice());
        if (listener != null) {
            holder.baobei_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.OnItemClick(v, position);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_photo;
        TextView tv_name;
        TextView tv_content;
        TextView tv_money;
        LinearLayout baobei_layout;

        public ViewHolder(View itemView) {
            super(itemView);

            iv_photo = (ImageView) itemView.findViewById(R.id.iv_photo);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_content = (TextView) itemView.findViewById(R.id.tv_yongHuPinJia);
            tv_money = (TextView) itemView.findViewById(R.id.et_money);
            baobei_layout = (LinearLayout) itemView.findViewById(R.id.baobei_layout);
        }
    }
}
